<template>
  <div
    v-for="(item, i) in list"
    :ref="
      (el) => {
        if (el) divs[i] = el;
      }
    "
    :key="i"
  >
    {{ item }}
  </div>
</template>
<script lang="ts">
import { defineComponent, ref, reactive, onBeforeUpdate } from "vue";

export default defineComponent({
  setup() {
    const list = reactive([1, 2, 3]);
    const divs = ref([]);

    // 确保在每次更新之前重置ref
    onBeforeUpdate(() => {
      divs.value = [];
    });

    return {
      list,
      divs,
    };
  },
});
</script>
<style lang="scss" scoped></style>
